import tkinter as tk
from tkinter import messagebox
from RegisterPage import RegistertPage
from db import db
from MainPage import MainPage
class LoginPage:
    # 显示主登录界面
    def __init__(self, root):
        self.root = root
        db.create_json('downwork.json')
        db.create_json('users.json')
        db.create_json('upwork.json')
        db.create_json('leave.json')
        db.create_json('staff.json')
        # 获取账号和密码的值
        self.username = tk.StringVar()
        self.password = tk.StringVar()

        self.frame = tk.Frame(self.root)
        self.frame.pack()
        tk.Label(self.frame, text="欢迎登录员工管理系统", anchor="center", fg="red").grid(row=0, column=1, pady=20, columnspan=2)
        # 账号文本框的布局
        tk.Label(self.frame, text="账号: ").grid(row=1, column=1, pady=10)
        self.e1 = tk.Entry(self.frame, textvariable=self.username)
        self.e1.grid(row=1, column=2, pady=10)

        tk.Label(self.frame, text="密码: ").grid(row=2, column=1, pady=10)
        self.e2 = tk.Entry(self.frame, textvariable=self.password)
        self.e2.grid(row=2, column=2, pady=10)

        tk.Button(self.frame, text="登录", command=self.my_login).grid(row=3, column=1, pady=10, sticky='e')
        tk.Button(self.frame, text="注册", command=self.my_register).grid(row=3, column=2, pady=10, sticky='e')

    # 注册按钮的功能
    def my_register(self):
        self.frame.pack_forget()
        RegistertPage(self.root, self.frame)


    # 登录按钮的功能
    def my_login(self):

        self.username = self.e1.get()
        self.password = self.e2.get()
        MainPage(self.frame, self.root).function_login(self.username, self.password)












if __name__ == '__main__':
    root = tk.Tk()
    root.geometry('400x280')
    root.title('企业员工登录系统')
    LoginPage(root)
    root.mainloop()